package com.sikao.app.utils;

import android.text.InputFilter;
import android.text.Spanned;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.sikao.app.app.MyApplication;
import com.sikao.app.net.OkHttpHelper;

import java.math.BigDecimal;

/**
 * Created by Sun on 2016/7/11.
 */
public class Utils {
 public static void showLog(String content){
     if(ConstantClass.isShowLog) {
         Log.d(OkHttpHelper.TAG, content);
     }
 }
 public static void showToast(String content){
     Toast.makeText(MyApplication.getInstance(),content,Toast.LENGTH_SHORT).show();
     Utils.showLog("=====Util:"+content);
 }
    public static void jsOption(String sat ,String mess) {

    }
 public static String addPoints(String content,int len){
     if(content.length()>len){
      content  = content.substring(0,(len-1))+"..";
     }
    return content;
 }

    public static boolean isNum(String str) {//判断是不是数字

        try {
            new BigDecimal(str);
            return true;
        } catch (Exception e) {
            return false;
        }
    }

      class  s implements EditText.OnEditorActionListener {

          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
              return false;
          }
      }

    /**
     *  设置小数位数控制
     */
    /**
     * 判断字符串是否是整数
     */
    public static boolean isInteger(String value) {
        try {
            Integer.parseInt(value);
            return true;
        } catch (NumberFormatException e) {
            return false;
        }
    }
    /**
     * 判断字符串是否是浮点数
     */
    public static boolean isDouble(String value) {
        try {
            Double.parseDouble(value);
            return value.contains(".");
        } catch (NumberFormatException e) {
            return false;
        }
    }
    /**
     * 判断字符串是否是数字
     */
    public static boolean isNumber(String value) {
        return isInteger(value) || isDouble(value);
    }
    /**
     *
     * 提供精确的小数位四舍五入处理。
     *
     * @param v
     *            需要四舍五入的数字
     *
     * @param scale
     *            小数点后保留几位
     *
     * @return 四舍五入后的结果
     *
     */

    public static String roundForNumber(String v,int scale) {
        if (scale < 0) {
            throw new IllegalArgumentException("The scale must be a positive integer or zero");
        }

        BigDecimal b = new BigDecimal(v);

        b = b.setScale(scale, BigDecimal.ROUND_HALF_UP); //四舍五入
        return b + "";
    }
}
